#include <string>
#include <vector>
using namespace std;
class Solution {
public:
    string minWindow(string S, string T) {
        if (T.size()==0) return "";
        vector<int> count(256, 0);
        int sum=0;
        for (int i=0;i<T.size();i++) {
            if (count[(unsigned char)T[i]]==0) ++sum;
            ++count[(unsigned char)T[i]];
        }
        string ans="";
        for (int h=0,t=0;t<S.size();t++) {
            --count[(unsigned char)S[t]];
            if (count[(unsigned char)S[t]]==0) --sum;
            while (sum==0 && h<=t) {
                if (sum==0 && (ans=="" || ans.size()>t-h+1)) ans=S.substr(h, t-h+1);
                if (count[(unsigned char)S[h]]==0) ++sum;
                ++count[(unsigned char)S[h]];
                ++h;
            }
        }
        return ans;
    }
};
